package com.huanwei.questionfragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.huanwei.cc.R;
import com.huanwei.cc.base.MyApplication;
import com.huanwei.cc.bean.Life_MSG2;
import com.huanwei.cc.bean.MyEvent;
import com.huanwei.cc.db.Z_DHD_Dao;
import com.huanwei.cc.db.Z_Login_UserInfoDao;
import com.huanwei.cc.ui.EditTextDialog3;
import com.huanwei.mainfragment.MainActivity;
import com.huanwei.questionfragment.adapter.Waite_Answered2_Adapter;
import com.huanwei.questionfragment.adapter.Waite_Answered_Adapter;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

/**
 * Created by zhuwenhai on 2017/12/1.
 * 待回答
 */

public class DHD_Activity extends AppCompatActivity {


//    public static DHD_Activity newInstance() {
//        Bundle args = new Bundle();
//        DHD_Activity fragment = new DHD_Activity();
//        fragment.setArguments(args);
//        return fragment;
//    }

    Z_DHD_Dao z_msgDao;
    ListView lvList;
    Waite_Answered2_Adapter bank_card_adapter;
    @OnClick(R.id.img_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ax_share);
        ButterKnife.bind(this);
        initViewsAndEvents();
    }
//    public View onCreateView(LayoutInflater inflater, ViewGroup container,
//                             Bundle savedInstanceState) {
//        if (view == null) {
//            view = View.inflate(getActivity(), R.layout.fragment_share, null);
//            ButterKnife.bind(this, view);
//            initViewsAndEvents();
//        }
//        ViewGroup parent = (ViewGroup) view.getParent();
//        if (parent != null) {
//            parent.removeView(view);
//        }
//
//        return view;
//    }


    public void initViewsAndEvents() {
        EventBus.getDefault().register(this);

        lvList = (ListView) findViewById(R.id.lv_list);//设置;
        lvList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            }
        });
        z_msgDao = new Z_DHD_Dao(MyApplication.getInstance());
        List<Life_MSG2> query = z_msgDao.query();
        bank_card_adapter = new Waite_Answered2_Adapter();
        bank_card_adapter.setactivity(DHD_Activity.this, z_msgDao);
        lvList.setAdapter(bank_card_adapter);
        bank_card_adapter.addItem(query);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    public void onEventMainThread(MyEvent event) {

        if (!TextUtils.isEmpty(event.getType())) {
            if (event.getType().equals("shua")) {
                List<Life_MSG2> query = z_msgDao.query();
                lvList.setAdapter(bank_card_adapter);
                bank_card_adapter.clear();
                bank_card_adapter.addItem(query);
            }
        }
    }

    public void shuaxin() {
        List<Life_MSG2> query = z_msgDao.query();
        lvList.setAdapter(bank_card_adapter);
        bank_card_adapter.clear();
        bank_card_adapter.addItem(query);

    }
}